package com.example.wangyuyuan.androidframe.mvp.ui;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.wangyuyuan.androidframe.R;
import com.example.wangyuyuan.androidframe.mvp.base.BaseActivity;

import butterknife.BindView;

/**
 * Created by wangyuyuan on 2017/5/18.
 */

public class RegisterActivity extends BaseActivity {

    @BindView(R.id.ivToolbarNavigation)
    ImageView ivToolbarNavigation;
    @BindView(R.id.tvToolbarTitle)
    TextView tvToolbarTitle;
    @BindView(R.id.etPhone)
    EditText etPhone;
    @BindView(R.id.etPwd)
    EditText etPwd;
    @BindView(R.id.ivSeePwd)
    ImageView ivSeePwd;
    @BindView(R.id.etVerifyCode)
    EditText etVerifyCode;
    @BindView(R.id.btnSendCode)
    Button btnSendCode;
    @BindView(R.id.btnRegister)
    Button btnRegister;
    @BindView(R.id.etNick)
    EditText etNick;

    @Override
    protected void processLogic() {

    }

    @Override
    protected void setListener() {
        ivToolbarNavigation.setOnClickListener(this);
        btnSendCode.setOnClickListener(this);
        btnRegister.setOnClickListener(this);
        etNick.addTextChangedListener(watcher);
        etPhone.addTextChangedListener(watcher);
        etPwd.addTextChangedListener(watcher);
        etVerifyCode.addTextChangedListener(watcher);

    }

    @Override
    protected void findViewById() {

    }

    @Override
    protected void loadViewLayout() {
        setContentView(R.layout.regist_ac_layout);

    }

    @Override
    protected Context getActivityContext() {
        return this;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ivToolbarNavigation://返回
                finish();
                break;
            case R.id.btnSendCode://发送验证码
                sendCode();
                break;
            case R.id.btnRegister://注册
                register();
                break;
        }

    }

    //注册新用户
    private void register() {
    }

    //发送验证码方法
    private void sendCode() {
    }

    //    edittext监听事件类
    TextWatcher watcher = new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            btnRegister.setEnabled(canRegister());
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    };

    //    判断注册按钮是否可以点击
    private boolean canRegister() {
        int nikeNameLength = etNick.getText().toString().trim().length();
        int phoneLength = etPhone.getText().toString().trim().length();
        int pwd = etPwd.getText().toString().trim().length();
        int verticode = etVerifyCode.getText().toString().trim().length();
        if (nikeNameLength > 0 && phoneLength == 11 && pwd > 6 && verticode > 0) {
            return true;
        }
        return false;
    }
}
